import { Component, OnInit } from '@angular/core';
import { CarouselConfig } from 'ngx-bootstrap/carousel';
import {Router} from '@angular/router';
import {adSystemApiUrl,AliyunOssOutputUrl} from '../../../config/api';
import {HttpService} from '../../lib/service/http.service';
import {LocalStorageService} from '../../lib/service/local-storage.service';

@Component({
  selector: 'app-index',
  templateUrl: './index.component.html',
  styleUrls: ['./index.component.scss'],
  providers: [ {provide: CarouselConfig, useValue: {interval: 5000, noPause: true}},LocalStorageService ]
})
export class Index2Component implements OnInit {

  type: string;
  message: string;
  isShow = false;

  newestInfo: any;  //最新资讯
  aliyunOssOutputUrl: string = AliyunOssOutputUrl;
  constructor(private httpService: HttpService,
              private router: Router,
              private localStorageService: LocalStorageService) { }

  ngOnInit() {
    this.getArtical();
  }

  //获取最新资讯
  getArtical(){
    const url = `${adSystemApiUrl}/v1/fddata/posts/list`;
    return this.httpService.httpGetAuth(url).subscribe(
      data => {
        this.newestInfo = data.data.data;
      }
    )
  }

  // 点击轮播图跳转页面
  turnPage() {
    const auth = this.localStorageService.getUserInfo();
    if (!auth) {
      this.type = 'info';
      this.message = '请先登录';
      this.isShow = true;
      return false;
    }
    this.router.navigate(['/main/index']);
  }

  // 跳转到新闻详情页
  turnNewsDetail(data: any) {
    this.router.navigate(['/home/news-detail/' + data.id], {queryParams: {categoryId: data.category_id}});
  }
}
